﻿<?php
   	include_once('class/autoload.php');
   	$PARAM_hote='localhost'; // le chemin vers le serveur
   	$PARAM_utilisateur='root'; // nom d'utilisateur pour se connecter
    $PARAM_mot_passe=''; // mot de passe de l'utilisateur pour se connecter
	$PARAM_nom_bd='ppetesttab';
	
	$site = new page_secur('tableau');
	
	$varx= new PDO('mysql:host='.$PARAM_hote.';dbname='.$PARAM_nom_bd, $PARAM_utilisateur, $PARAM_mot_passe,array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
	
	$requete = 'SELECT * FROM eleve';
	$tab = $varx->query($requete);
	$a="";
	$b="";
	$r="";
	$c = "";
	$AutorisationChecked = "";
	$DroitImageChecked = "";
	$CertificatChecked = "";
	$v = "
						echo '<div style='float: right;margin-top:'><form method='post'>
						<p>
						<input name='deconnex' type='submit' value='Déconnexion' />
					</p>
					</form></div>';
	
<div class=\"table-title\">
<center><h3>Eleve</h3></center>
</div>
<table class=\"table-fill\">
<thead>
<tr>
<th class=\"text-left\">Nom</th>
<th class=\"text-left\">PrÃ©nom</th>
<th class=\"text-left\">Date de Naissance</th>
<th class=\"text-left\">Classement (A ou B)</th>
<th class=\"text-left\">Autorisation Parent</th>
<th class=\"text-left\">Certificat</th>
<th class=\"text-left\">Droit Image</th>
<th class=\"text-left\">NÂ°Licence</th>
<th class=\"text-left\"></th>
</tr>
</thead>
<tbody class=\"table-hover\">";
	
	while ($row = $tab->fetch(PDO::FETCH_OBJ))
	{
		if($row->Classement == "A")
		{$a="selected";}
		else if($row->Classement == "B")
		{$b="selected";}
		else if($row->Classement == "R")
		{$r="selected";}
		else
		{}
		if ($row->AutorisationParent==0 || $row->AutorisationParent== NULL)
		{
			$AutorisationChecked = "";
		}
		else
		{
			$AutorisationChecked = "Checked";
		}
	
		if ($row->Certificat==0 || $row->Certificat== NULL)
		{
			$CertificatChecked = "";
		}
	
		else
		{
			$CertificatChecked = "Checked";
		}
	
		if ($row->DroitImage==0 || $row->DroitImage== NULL)
		{
			$DroitImageChecked = "";
		}
		else
		{
			$DroitImageChecked = "Checked";
		}
		/*
		 if (isset ($_POST["Modifier$row->ID"]))
		 {
		 if ($_POST["Modifier$row->ID"] == $row->ID)
		 {
		 $c = $c."<tr>
		 <td class=\"text-left\"><input type=\"text\" name=\"Nom\" value=\"$row->Nom\"/></td>
		 <td class=\"text-left\"><input type=\"text\" name=\"Prenom\" value=\"$row->Prenom\"/></td>
		 <td class=\"text-left\"><input type=\"date\" name=\"DateNaiss\" value=\"$row->DateNaiss\"/></td>
		 <td class=\"text-center\">
		 <FORM>
		 <SELECT name=\"nom\" size=\"1\">
		 <OPTION ".$a." value=\"A\" >A</OPTION>
		 <OPTION ".$b." value=\"B\" >B
		 <OPTION ".$r." value=\"R\" >Redoublant
		 </SELECT>
		 </FORM>
		 </td>
		 <td class=\"text-center\">
		 <input id=\"autorisation".$row->ID."\" type=\"checkbox\" name=\"autorisation\" $AutorisationChecked><label for=\"autorisation".$row->ID."\"><span class=\"ui\"></span></label>
		 </td>
		 <td class=\"text-center\"><p><input id=\"certificat".$row->ID."\" type=\"checkbox\" name=\"certificat\" $CertificatChecked><label for=\"certificat".$row->ID."\"><span class=\"ui\"></span></label></p></td>
		 <td class=\"text-center\"><p><input id=\"droitimage".$row->ID."\" type=\"checkbox\" name=\"droitimage\" $DroitImageChecked><label for=\"droitimage".$row->ID."\"><span class=\"ui\"></span></label></p></td>
		 <td class=\"text-left\"><input type=\"text\" name=\"numlicence\" value=\"$row->NumLicence\"/></td>
		 <td class=\"text-center modifier\">
		 <button onClick='Valider('$row->ID')'>Valider</button>
		 </td>
				
			</tr>";
			$r="";
			$b="";
			$a="";
			}
			}
			else
	
			{*/
		$IDEl = $row->ID;
		$c = $c."
			<tr>
			<td class='text-left'>".$row->Nom."</td>
			<td class='text-left'>".$row->Prenom."</td>
			<td class='text-left'>".$row->DateNaiss."</td>
			<td class='text-center'>
				<FORM>
    				<SELECT name='nom' size='1' disabled='disabled'>
    					<OPTION ".$a." value='A' >A</OPTION>
    					<OPTION ".$b." value='B' >B</OPTION>
    					<OPTION ".$r." value='R' >Redoublant</OPTION>
    				</SELECT>
    			</FORM>
    		</td>
			<td class='text-center'>
				<input id='autorisation".$row->ID."' type='checkbox' name='autorisation' $AutorisationChecked disabled='disabled'><label for='autorisation".$row->ID."'><span class='ui'></span></label>
					</td>
					<td class='text-center'><p><input id='.$IDEl.' type='checkbox' name='certificat' $CertificatChecked disabled><label for='certificat".$row->ID."'><span class='ui'></span></label></p></td>
			<td class='text-center'><p><input id='droitimage".$row->ID."' type='checkbox' name='droitimage' $DroitImageChecked disabled><label for='droitimage".$row->ID."'><span class='ui'></span></label></p></td>
				<td class='text-left'>$row->NumLicence</td>
				<td class='text-center modifier'>
				<button onclick='document.getElementById(\''.$IDEl.'\').disabled = false;'>Modifier</button>
				</td>
				</tr>";
		$r="";
		$b="";
		$a="";
	}/*".$row->ID."*/
	//}
	$site->corps = $v.$c."</tbody>
</table>";
	$site->titre = "Tableau Affichage";

	
	$site->affiche();
?>